
package bdd.beans;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import bdd.DBLink;
import beans.Etudiant;
import beans.Examen;
import beans.Note;

/**
 *
 * @author sojousse
 */
public class ListeNoteEns {
     private DBLink dblink;
     List<Note> listeNoteEns;

     public ListeNoteEns()
     {
         dblink = new DBLink();
         listeNoteEns = new ArrayList<Note>();
     }

     public ListeNoteEns(List<Note> listeNoteEns)
     {
         dblink = new DBLink();
         this.listeNoteEns = listeNoteEns;
     }

    public List<Note> getListeNoteEns()
    {
        return this.listeNoteEns;
    }

    public void setListeNoteEns(List<Note> listeNoteEns)
    {
        this.listeNoteEns=listeNoteEns;
    }

    public void add(Note note)
    {
        this.listeNoteEns.add(note);
    }

    public void recupererListeNoteEns(int numEtudiant, int promotion, int ec, int numEnseignant, int numeroExamen){
      try
      {
            DBLink db = new DBLink();
            db.connexion();
            String rq = "select NOTE.NUMETUDIANT, NOTE.NOTE, NOTE.NUMEXAMEN, EXAMEN.LIBELLE "
                    + "from NOTE,ENSEIGNANT,PROMOTION,EC,JNTTYPEECENSEIGNANT,JNTETUDIANTPROMOTION, Examen "
                    + "where EC.NUMEC=JNTTYPEECENSEIGNANT.NUMEC AND "
                    + "JNTTYPEECENSEIGNANT.NUMENSEIGNANT=ENSEIGNANT.NUMENSEIGNANT AND "
                    + "NOTE.NUMETUDIANT=JNTETUDIANTPROMOTION.NUMETUDIANT AND "
                    + "PROMOTION.NUMPROMOTION=JNTETUDIANTPROMOTION.NUMPROMOTION "
                    + " and note.numexamen=examen.numexamen "
                    + " and JNTETUDIANTPROMOTION.NUMETUDIANT=" + numEtudiant
                    + " and Enseignant.numenseignant=" + numEnseignant
                    + " and promotion.numPromotion=" + promotion
                    + " and EC.numEC=" + ec
                    + " and note.numexamen=" + numeroExamen
                    + " order by note.numetudiant, note.numexamen";

            PreparedStatement pst = db.getConnection().prepareStatement(rq);
            System.out.println(rq);
            Note n = new Note();
            Etudiant e = new Etudiant();
            Examen ex = new Examen();
            db.setPst(pst);
            ResultSet rs = db.getPst().executeQuery();
            db.setRs(rs);

            while(db.getRs().next())
            {
                n=new Note();
                e=new Etudiant();
                e.setNumEtudiant(db.getRs().getInt("numetudiant"));
                n.setUnEtudiant(null);
                n.setUneNote(db.getRs().getInt("note"));
                ex=new Examen();
                ex.setNumExamen(db.getRs().getInt("numexamen"));
                n.setUnExamen(ex);
                this.listeNoteEns.add(n);
            }
            db.getConnection().close();
      }
      catch (SQLException ex)
      {
            Logger.getLogger(ListeECEns.class.getName()).log(Level.SEVERE, null, ex);
      }
  }

}
